<template>
  <div class="main-warp-two">
    <div
      class="main-two-text"
      v-for="(item, index) in discoveryList"
      :key="index"
    >
      <div class="two-div">{{ item.label }}:</div>
      <div class="two-text">
        <span
          v-for="(em,idx) in item.choises"
          :key="em.id"
          @click="tabHadler(item, idx)"
          :class="em.isCheck ? 'active' : ''"
          >{{ em.name }}</span
        >
      </div>
    </div>
    <div class="two-reset" v-if="reset" @click="resetHadler">
      <span>重置</span>
    </div>
    <p class="main-two-P" @click="openOrShow">
      {{ show ? "展开全部" : "收起" }}
    </p>
  </div>
  <div class="main-warp-three">
    <span :class="volume == 1?'active':''" @click="volumeHadler(1,'integrated')">{{volume == 1?'综合排序':'综合'}}</span>
    <span :class="volume == 2?'active':''" @click="volumeHadler(2,'sellCountDesc')">{{volume == 2?'销量由高到低':'销量'}}</span>
    <span :class="volume == 3?'active':''" @click="volumeHadler(3,'viewCountDesc')">{{volume == 3?'浏览量由高到低':'浏览量'}}</span>
    <span class="money" :class="volume == 4 || volume == 5?'active':''" @mouseenter="flage = true" @mouseleave="flage = false">{{volume==4?'价格由高到低':volume==5?'价格由低到高':'价格'}} <el-icon size="12px"><ArrowDown /></el-icon
    >   
    <!-- v-show="flage"  -->
      <div class="card-header" v-show="flage">
        <div class="button" @click="volumeHadler(4,'priceDesc')">价格由高到低</div>
        <div class="button" @click="volumeHadler(5,'priceAsc')">价格由低到高</div>
      </div>
    </span>
    <span :class="volume == 6?'active':''" @click="volumeHadler(6,onsellTimeDesc)">{{volume == 6?'发布时间由近及远':'发布时间'}}</span>
  </div>
</template>

<script lang="ts">
export default {
  name: "SecondLevel",
};
</script>

<script setup lang="ts">
import useDiscoveryStore from "@/store/discovery";
import { computed, onMounted, ref } from "vue";
import { ElMessage } from "element-plus";
import type { properMdeol } from "@/api/discovery";
const discoveryStore = useDiscoveryStore();

// 展开/收起
const show = ref(true);
const openOrShow = () => {
  show.value = !show.value;
};

// 重置
const reset = ref(false);

const discoveryList = computed(() => {
  return show.value
    ? (discoveryStore.seconList as []).slice(0, 2): discoveryStore.seconList;
});

// 点击标签
interface filterModel {
  filterCode:string
  filterValue:string[]
}

let data = {
      filterInfo:<filterModel[]>[]
    }
const tabHadler = (item: properMdeol, idx: number) => {
  const num = item.choises.reduce((pero, em) => {    
    return pero + Number(!!em.isCheck);
  }, 0);
  
  if (num > 2 ) {
    if(item.choises[idx].isCheck){
      item.choises[idx].isCheck = false
    }else{
      ElMessage.info("同一筛选条件最多选择3个");
    }
  } else {
    item.choises[idx].isCheck = !item.choises[idx].isCheck
  }

  if (num >= 0) {
    reset.value = true;
    // id
    let res = item.choises.filter(em =>{
      if(em.isCheck){
        return em.id
      }
    })
    let filterValue = []
    filterValue.push(res.map(it => it.id).toString())
    
    let lastData = {
      filterCode:item.name,
      filterValue
    }

    if(data.filterInfo.some(im => im.filterCode == lastData.filterCode)){
        data.filterInfo.filter(em => {
          if(em.filterCode == lastData.filterCode){
            em.filterValue.push(lastData.filterValue.toString())
          }
        })
    }
    
    data.filterInfo.push(lastData)
    discoveryStore.getVideoList(20,0,'sellCountDesc',data)
  }
};

// 重置
const resetHadler = () => {
  discoveryList.value.forEach((item) => {
    item.choises.forEach((em) => (em.isCheck = false));
  });
  reset.value = false;
  discoveryStore.getVideoList(20,0)
};


// 控制销量的默认样式
const volume = ref(1);
const flage = ref(false)
const eject = ref(true)
// 销量
const volumeHadler = (num:number,type:string)=>{
    discoveryStore.getVideoList(20,0,type)
    volume.value = num
}


onMounted(() => {
  discoveryStore.getMomberList();
});
</script>

<style scoped lang="less">
.main-warp-two {
  margin-top: 15px;
  width: 1200px;
  background-color: white;
  border-radius: 10px;
  padding: 32px 30px;
  box-sizing: border-box;
  position: relative;
  .main-two-text {
    display: flex;
    font-size: 14px;
    margin-bottom: 10px;
    .two-div {
      color: #b1b5c1;
      margin-right: 40px;
    }
    .two-text {
      width: 90%;
      display: flex;
      flex-wrap: wrap;
      span {
        display: inline-block;
        margin-right: 40px;
        color: #7d8090;
        margin-bottom: 20px;
        padding: 2px 4px;
        &.active {
          background-color: #f93684;
          color: white;
          border-radius: 2px;
        }
      }
    }
  }
  .two-reset {
    position: absolute;
    right: 30px;
    top: 32px;
    & > span {
      color: #f93684;
      font-size: 14px;
    }
  }
  .main-two-P {
    width: 100%;
    text-align: center;
    font-size: 14px;
    color: #f93684;
    margin-top: 20px;
  }
}
.main-warp-three {
  margin-top: 15px;
  width: 1200px;
  background-color: white;
  border-radius: 10px;
  padding: 26px 30px;
  box-sizing: border-box;
  display: flex;
  span {
    color: #7d8090;
    font-size: 14px;
    margin-right: 90px;
    &.active {
      color: #f93684;
    }
    &:hover {
      color: #f93684;
    }
    &.money{
    position: relative;
    box-sizing: border-box;
    .card-header{
      width: 130px;
      height: 100px;
      position: absolute;
      background-color: white;
      top: -14px;
      left: -50px;
      box-shadow: 0 0 10px 2px #ddd;
      border-radius: 4px;
      font-size: 14px;
      text-align: center;
      line-height: 50px;
      z-index: 1;
      .button{
        &:hover{
          background-color: rgb(252, 223, 234);
          color: #f93684;
        }
      }
    }
    
  }
  }
  
}
</style>
